//
//  LCComposeController.swift
//  SinaWeiBo
//
//  Created by mac on 16/12/11.
//  Copyright © 2016年 heima. All rights reserved.
//

import UIKit

class LCComposeController: UIViewController {
    
    //懒加载一个label
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        
        label.textColor = UIColor.darkGray
        label.font = UIFont.systemFont(ofSize: 17)
        //设置label换行
        label.numberOfLines = 0
        
        if let name = LCOAuthViewModel.sharedViewModel.userAccount?.name{
            let result = "发微博\n\(name)"
            //1获取文本附件
            let attributedStr = NSMutableAttributedString(string: result)
            
            //2获取到需要添加文本附件的区间
            let range = (result as NSString).range(of: name)
            
            //3把指定区间的内容转换成富文本
            attributedStr.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 12), NSForegroundColorAttributeName: UIColor.brown], range: range)
            
            //给label赋值
            label.attributedText = attributedStr

        }else{
            label.text = "发微博"
        }
        label.sizeToFit()
        label.textAlignment = .center
        return label
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    private func setupUI(){
        view.backgroundColor = randomColocr()
        
        setupNav()
        
    }
    //设置naviBar
    private func setupNav(){
        //设置取消itemBarButton
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "取消", target: self, action: #selector(cancleAction))
        //设置中间titleView
        self.navigationItem.titleView = titleLabel
        
    }
    
    @objc private func cancleAction(){
        
        self.dismiss(animated: true, completion: nil)
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

}
